package com.LeeCode;

/**
 * 正整数和负整数的最大计数
 */

public class Code2529 {
    public static void main(String[] args) {
        int[] nums = {5, 20, 66, 1314};
        System.out.println(new Code2529().maximumCount(nums));
    }

    public int maximumCount(int[] nums) {
        int start0 = lowerBound(nums, 0), end0 = lowerBound(nums, 1) - 1;

        int posNum = nums.length - end0 - 1;
        return Math.max(start0, posNum);
    }

    private int lowerBound(int[] nums, int target) {
        int left = -1, right = nums.length, mid;
        while (left + 1 < right) {
            mid = left + (right - left) / 2;
            if (nums[mid] >= target) {
                right = mid;
            } else {
                left = mid;
            }
        }
        return right;
    }
}
